﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Hxsoft.AppV1.Module;

namespace Hxsoft.AppV1.Admin.LinkManage.Controls
{
	public partial class SettedLink : BaseUserControl
	{	
		protected void Page_Load(object sender, EventArgs e)
		{
			if(!IsPostBack)
				this.DataBind();
		}

		/// <summary>
		/// 属性 IsEffective
		/// </summary>
		public bool IsEffective
		{
			get
			{
				return Convert.ToBoolean(CtrlIsEffective.Text);
			}
			set
			{
				CtrlIsEffective.Text = value.ToString();
			}
		}

		/// <summary>
		/// 属性 OrderNumber
		/// </summary>
		public int? OrderNumber
		{
			get
			{
				if (String.IsNullOrEmpty(CtrlOrderNumber.Text))
					return null;

				return Convert.ToInt32(CtrlOrderNumber.Text);
			}
			set
			{
				if (value == null)
					CtrlOrderNumber.Text = "";
				else
					CtrlOrderNumber.Text = value.ToString();
			}
		}

		public string ChannelIds
		{
			get
			{
				return StringExtensions.CasingCompound<string>(CBLChannelIds.Values, Companies.OperationTypeSeparator);
			}
			set
			{
				if (!string.IsNullOrEmpty(value))
				{
					CBLChannelIds.DataBind();
					CBLChannelIds.Values = StringExtensions.CasingDecompound<string>(value, Companies.OperationTypeSeparator);
				}
			}
		}

		/// <summary>
		/// 控件的 LinkInfo 实例。
		/// </summary>
		public Module.Link Info
		{
			get
			{
				Module.Link link = new Module.Link();

				link.OrderNumber = OrderNumber;
				link.IsEffective = IsEffective;
				link.ChannelIds = ChannelIds;

				return link;
			}
			set
			{
				if (value == null) return;
				ChannelIds = value.ChannelIds;
				OrderNumber = value.OrderNumber;
				IsEffective = value.IsEffective;
				
			}
		}
	}
}